
/*
  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is core2: ECMAScript core objects 2nd gig AS2. 
  
  The Initial Developer of the Original Code is
  Zwetan Kjukov <zwetan@gmail.com>.
  Portions created by the Initial Developer are Copyright (C) 2003-2006
  the Initial Developer. All Rights Reserved.
  
  Contributor(s):
*/

import buRRRn.ASTUce.*;

class Tests.core2.ObjectTest extends TestCase
    {
    
    function ObjectTest( name:String )
        {
        super( name );
        }
    
    function testConstructor()
        {
        //OBJ_000
        }
    
    function testClone()
        {
        var obj1, obj2;
        
        obj1 = { A:"hello", B:"world" };
        obj2 = obj1.clone();
        
        assertSame( obj1, obj2,   "OBJ_001a" );
        assertEquals( obj1, obj2, "OBJ_001b" );
        }
    
    function testConstructorProperty()
        {
        var arr1, bool1, dat1, err1, fct1, num1, obj1, str1;
        
        arr1 = [1,2,3];
        bool1 = true;
        dat1 = new Date();
        err1 = new Error( "test" );
        fct1 = function() { return "hello world"; };
        num1 = 12345;
        obj1 = {a:1, b:2};
        str1 = "hello world";
        
        assertTrue( arr1.constructor  == Array,    "OBJ_002a" );
        assertTrue( bool1.constructor == Boolean, "OBJ_002b" );
        assertTrue( dat1.constructor  == Date,     "OBJ_002c" );
        assertTrue( err1.constructor  == Error,    "OBJ_002d" );
        assertTrue( fct1.constructor  == Function, "OBJ_002e" );
        assertTrue( num1.constructor  == Number,   "OBJ_002f" );
        assertTrue( obj1.constructor  == Object,   "OBJ_002g" );
        assertTrue( str1.constructor  == String,   "OBJ_002h" );
        }
    
    function testCopy()
        {
        var obj1, obj2;
        
        obj1 = { A:"hello", B:"world" };
        obj2 = obj1.copy();
        
        assertNotSame( obj1, obj2,   "OBJ_003a" );
        assertEquals( obj1, obj2,    "OBJ_003b" );
        }
    
    function testEquals1()
        {
        var obj1, obj2;
        
        obj1 = { A:"hello", B:"world" };
        obj2 = { A:"hello", B:"world" };
        
        assertEquals( obj1, obj1,        "OBJ_004a" );
        assertTrue( obj1.equals( obj2 ), "OBJ_004b" );
        assertEquals( obj1, obj2,        "OBJ_004c" );
        }
    
    function testEquals2()
        {
        var obj1, obj2;
        
        obj1 = { A:"hello", B:"world" };
        obj2 = { A:"hello", B:"world", C:"test" };
        
        assertEquals( obj1, obj2, "OBJ_005" );
        }
    
    function testEquals3()
        {
        var obj1, obj2;
        
        obj1 = { A:"hello", B:"world", C:"test" };
        obj2 = { A:"hello", B:"world"};
        
        assertFalse( obj1.equals( obj2 ), "OBJ_006" );
        }
    
    function testHasOwnProperty()
        {
        var obj1;
        
        obj1 = new Object();
        obj1.test = "hello world";
        
        assertTrue( obj1.hasOwnProperty( "test" ),      "OBJ_007" );
        assertFalse( obj1.hasOwnProperty( "toString" ), "OBJ_007" );
        }
    
    function testHasProperty()
        {
        var obj;
        
        obj = {};
        obj.hello = "world";
        
        assertTrue( obj.hasProperty( "hello" ),    "OBJ_008a" );
        assertFalse( obj.hasProperty( "world" ),   "OBJ_008b" );
        assertTrue( obj.hasProperty( "toString" ), "OBJ_008c" );
        }
    
    function testIsPrototypeOf()
        {
        var obj1;
        
        obj1 = new Array();
        
        assertTrue( Array.prototype.isPrototypeOf( obj1 ),    "OBJ_009a" );
        assertTrue( Object.prototype.isPrototypeOf( obj1 ),   "OBJ_009b" );
        assertFalse( Boolean.prototype.isPrototypeOf( obj1 ), "OBJ_009c" );
        }
    
    function testMemberwiseClone()
        {
        var obj1, obj2, arr1;
        
        arr1 = [1,2,3];
        obj1 = {a:arr1,b:true,c:123};
        obj2 = obj1.memberwiseClone();
        
        assertEquals( obj1, obj2,     "OBJ_010a" );
        assertNotSame( obj1, obj2,    "OBJ_010b" );
        assertEquals( obj1.a, obj2.a, "OBJ_010c" );
        assertSame( obj1.a, obj2.a,   "OBJ_010d" );
        }
    
    function testMemberwiseCopy()
        {
        var obj1, obj2, arr1;
        
        arr1 = [1,2,3];
        obj1 = {a:arr1,b:true,c:123};
        obj2 = obj1.memberwiseCopy();
        
        assertEquals( obj1, obj2,      "OBJ_011a" );
        assertNotSame( obj1, obj2,     "OBJ_011b" );
        assertEquals( obj1.a, obj2.a,  "OBJ_011c" );
        assertNotSame( obj1.a, obj2.a, "OBJ_011d" );
        }
    
    function testPropertyIsEnumerable()
        {
        var obj1, obj2;
        
        obj1 = {};
        obj1.test = "hello world";
        
        assertTrue( obj1.propertyIsEnumerable( "test" ),                  "OBJ_012a" );
        assertFalse( obj1.propertyIsEnumerable( "something" ),            "OBJ_013b" );
        
        /* note:
           as we can't define the DontEnum attribute (except for ActionScript)
           we have to test on build-in property we know
           are not enumerable.
        */
        assertFalse( Object.prototype.propertyIsEnumerable( "toString" ), "OBJ_012c" );
        assertFalse( _global.propertyIsEnumerable( "Object" ),            "OBJ_012d" );
        }
    
    function testReferenceEquals()
        {
        var obj1, obj2, obj3, obj4;
        
        obj1 = { A:"hello", B:"world"};
        obj2 = obj1;
        obj3 = { A:"hello", B:"world"};
        obj4 = obj1.clone();
        
        assertTrue( obj1.referenceEquals( obj2 ),  "OBJ_013a" );
        assertFalse( obj1.referenceEquals( obj3 ), "OBJ_013b" );
        assertFalse( obj1.referenceEquals( null ), "OBJ_013c" );
        assertTrue( obj1.referenceEquals( obj4 ),  "OBJ_013d" );
        }
    
    function testToBoolean()
        {
        //OBJ_014
        }
    
    function testToNumber()
        {
        //OBJ_015
        }
    
    function testToObject()
        {
        //OBJ_016
        }
    
    function testToPrimitive()
        {
        //OBJ_017
        }
    
    function testToSource()
        {
        var obj1, obj2;
        var src1, src2;
        
        obj1 = {a:0,b:1,c:3,d:true,e:null,f:"hello",g:"world"};
        src1 = "{a:0,b:1,c:3,d:true,e:null,f:\"hello\",g:\"world\"}"
        
        obj2 = {a:[1,2,3],b:{x:0,y:0},c:new String("hello"),d:new Date(2005,03,30)};
        src2 = "{a:[1,2,3],b:{x:0,y:0},c:\"hello\",d:new Date(2005,3,30)}";
        
        assertEquals( obj1.toSource(), src1, "OBJ_018a" );
        assertEquals( obj2.toSource(), src2, "OBJ_018b" );
        }
    
    
    }

